package com.pro.controller;

import com.pro.pojo.JsUserOrder;
import com.pro.pojo.JsonData;
import com.pro.service.JsUserCourseToBeCommentedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ClassName:JsUserCourseToBeCommentedController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2021/11/11 下午 4:37
 * @Author: WYH
 */
@Controller
@RequestMapping("/courseToBe")
public class JsUserCourseToBeCommentedController {

    @Autowired
    private JsUserCourseToBeCommentedService jsUserCourseToBeCommentedService;

    @RequestMapping("/getAllCourse")
    @ResponseBody
    public JsonData getAllCourse(String orderPaymentChannel, String orderSource) {
        orderPaymentChannel = orderPaymentChannel = !("null").equals(orderPaymentChannel) && orderPaymentChannel != null  ? "%"+orderPaymentChannel+"%":"%%";
        orderSource = orderSource = !("null").equals(orderSource) && orderSource != null ? "%"+orderSource+"%":"%%";
        List<JsUserOrder> allCourse = jsUserCourseToBeCommentedService.getAllCourse(orderPaymentChannel, orderSource);
        int count = jsUserCourseToBeCommentedService.count(orderPaymentChannel, orderSource);
        return allCourse != null ? JsonData.buildSuccess(allCourse,count):JsonData.buildError("服务端错误");
    }

    @RequestMapping("/delCourse")
    @ResponseBody
    public JsonData delCourse(Integer orderId) {
        Boolean aBoolean = jsUserCourseToBeCommentedService.delCourse(orderId);
        return aBoolean!= false ? JsonData.buildSuccess(aBoolean):JsonData.buildError("服务端错误");
    }

}
